package com.example.interface3;

// 定义第一套实现类，实现接口：实现打印学生信息，实现打印平均分。
public class ClassDataInterImpl1 implements ClassDataInter {

    private Student[] students;

    public ClassDataInterImpl1(Student[] students) {
        this.students = students;
    }

    @Override
    public void printAllStudentInfos() {
        System.out.println("全班学生信息如下：");
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            System.out.println(s.getName() + " " + s.getSex() + " " + s.getScore());
        }
    }

    @Override
    public void printAverageScore() {
        double sum = 0;
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            sum += s.getScore();
        }
        System.out.println("全班平均成绩为：" + sum / students.length);
    }
}
